#!/bin/bash
{
lld_mem_tmp="$(ps axh o rss,pid,comm O-r |head)"
lld_mem_log=/home/myzabbix/zabbix.lld.mem.log
echo "${lld_mem_tmp}" |awk '{R[NR]=1;F[NR,1]=$1;F[NR,2]=$2;F[NR,3]=$3;B[$3]++}END{
for (i in R) {
	for (j in B) {
		if (j==F[i,3])
			if (B[j]>1) print F[i,1],F[i,2]"_"F[i,3]; else print F[i,1],F[i,3]
		}
	}
}' > ${lld_mem_log}

originData="$(awk '{p[$NF]++}END{
for (i in p) print "{\"{#MEMTOP}\":\""i"\"}";
}' ${lld_mem_log})"
} 2>/dev/null
# 生成Json格式
echo "{\"data\":[`echo ${originData}|sed 's/ /,/g'`]}"